<form class="layui-form layui-form-pane" method="post" action="" enctype="multipart/form-data" >
    @csrf
    <div class="layui-form-item">
        <label class="layui-form-label">Banner</label>
        <button type="button" class="layui-btn" id="test3"><i class="layui-icon"></i>上传文件</button>
        <input type="hidden" name="picname" id="picname">
    </div>
    <div class="layui-form-item" >
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    //Demo
    layui.use('form', function(){
        var form = layui.form;
        form.render();

        layui.use('upload',function(){
            var $ = layui.jquery
                ,upload = layui.upload;
            //指定允许上传的文件类型
            upload.render({
                elem: '#test3'
                ,url: '/admin/banner_up' //改成您自己的上传接口
                ,accept: 'file' //普通文件
                ,done: function(res){
                    layer.msg(res.msg);
                    if(res.code == 1){
                        $("#test3").text('上传成功!');
                        $("#picname").val(res.info);
                    }
                }
            });
        });

        //监听提交
        form.on('submit(formDemo)', function(data){
            layer.confirm('确认执行此操作？', {icon: 3, title:'提示'}, function(index){
                ajax("{{url('admin/banner/insert')}}",data.field,function(data){
                    layer.close();
                    layer.closeAll();
                    layer.msg(data.msg);
                    if(data.code == 1){
                        location.href = '/admin/banner/index';
                    }
                });
            });
            return false;
        });
    });
</script>
